<template>
    <j-modal :title="title" :width="width" :visible="visible" switchFullscreen @ok="handleOk" @cancel="handleCancel"
        cancelText="关闭">
        <a-table ref="table" size="middle" :scroll="{ x: true }" :bordered="false" rowKey="id" :columns="columns"
            :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
            @change="handleTableChange">
            <template slot="autoSlot" slot-scope="text,record">
                <a-switch :checked="text == 1" @change="changeState(record)" checked-children="是"
                    un-checked-children="否" size="large" />
            </template>
            <span slot="action" slot-scope="text, record">
                <a @click="showManualRechargeModal(record)">手动储值</a>
                <a-divider type="vertical" />
                <a @click="">查看储值记录</a>
            </span>
        </a-table>
    </j-modal>
</template>

<script>
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, postAction } from '@api/manage'
export default {
    mixins: [JeecgListMixin, mixinDevice],
    data() {
        return {
            title: '储值记录',
            width: 1200,
            visible: false,
            userId: '',
            columns: [
                {
                    title: '操作时间',
                    align: "center",
                    dataIndex: 'createTime',
                },
                {
                    title: '最新储值变动时间',
                    align: "center",
                    dataIndex: 'updateTime',
                    customRender: function (t, r, index) {
                        console.log('t', t, 'r', r);
                        return r.updateTime ? r.updateTime : r.createTime;
                    }
                },
                {
                    title: '储值增加',
                    align: "center",
                    dataIndex: 'increase',
                    customRender: function (t, r, index) {
                        return r.source.indexOf('增加') != -1 ? r.amount : '----';
                    }
                },
                {
                    title: '储值减少',
                    align: "center",
                    dataIndex: 'reduce',
                    customRender: function (t, r, index) {
                        return r.source.indexOf('减少') != -1 ? r.amount : '----';
                    }
                },
                {
                    title: '备注',
                    align: "center",
                    dataIndex: 'source'
                },
            ],
            url: {
                list: "hc/hcUser/walletBalanceHistory",
                delete: "hc/hcCompanyInfo/delete",
            },
        }
    },
    methods: {
        show(id) {
            this.queryParam.id = id;
            this.visible = true;
            this.loadData();
        },
        loadData(arg) {
            if (!this.queryParam.id) {
                return
            }
            //加载数据 若传入参数1则加载第一页的内容
            if (arg === 1) {
                this.ipagination.current = 1;
            }
            var params = this.getQueryParams();//查询条件
            this.loading = true;
            postAction(this.url.list, params).then((res) => {
                if (res.success) {
                    //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
                    this.dataSource = res.result.records || res.result;
                    if (res.result.total) {
                        this.ipagination.total = res.result.total;
                    } else {
                        this.ipagination.total = 0;
                    }
                    //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
                } else {
                    this.$message.warning(res.message)
                }
            }).finally(() => {
                this.loading = false
            })
        },
        handleOk() {
            this.handleCancel();
        },
        handleCancel() {
            this.model = {};
            this.visible = false
        }
    }
}
</script>